package com.wc.alorithm_luogu._国赛模拟赛.E_序列合并;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/5/19 10:36
 * @description https://www.luogu.com.cn/problem/T440350?contestId=170180
 */
public class Main {
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 200010;
    static int[] a = new int[N];
    static int n, k;

    public static void main(String[] args) {
        n = sc.nextInt();
        k = sc.nextInt();
        int sum = 0;
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
            sum ^= a[i];
        }

        if (k == n - 2) {
            int res = 0;
            for (int i = 0; i < n; i++) {
                if (i == 1 || i == n - 2) continue;
                res = Math.max(res, (sum ^ a[i]) & a[i]);
            }
            if (n == 2) System.out.println(a[1] ^ a[2]);
            else System.out.println(res);
        } else if (n <= 20) {
            int res = 0;
            int[] backUp = new int[n];
            System.arraycopy(a, 0, backUp, 0, n);
            for (int i = 1; i < 1 << n; i++) {
                if (check(i) && (i >> n & 1) != 1) {
                    System.arraycopy(backUp, 0, a, 0, n);
                    int curRes = (1 << n) - 1;
                    for (int j = 0; j < n; j++) {
                        if ((i >> j & 1) == 1) {
                            a[j + 1] ^= a[j];
                            a[j] = 0;
                        } else curRes &= a[j];
                    }
                    res = Math.max(res, curRes);
                }
            }
            System.out.println(res);
        } else {

        }
    }

    static boolean check(int x) {
        int res = 0;
        for (int i = 0; i < n; i++) {
            res += x >> i & 1;
        }
        return res == k;
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}